<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewpoint" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>
    <link href="https://cdn.bootcss.com/semantic-ui/2.4.1/semantic.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.css" th:href="@{/lib/editormd/css/editormd.css}"/>
    <link href="../../static/css/myCss.css" rel="stylesheet">
</head>
<body>
<nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment my-padding-tb-mini my-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary menu stackable">
            <h2 class="ui header teal item">管理后台</h2>
            <a href="#" class="active my-item item my-mobile-hide">博客</a>
            <a href="#" class="my-item item my-mobile-hide">标签</a>
            <a href="#" class="my-item item my-mobile-hide">分类</a>

            <!--            头像-->
            <div class="my-item right menu my-mobile-hide">
                <div class="ui dropdown item">
                    <div class="text">
                        <img class="ui avatar image QR" src="../../static/images/pika.jpg">
                        登陆者用户名
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="menu tooggle ui icon black button my-top-right my-mobile-show"><i class="sidebar icon"></i></a>
</nav>

<div class="ui menu attached pointing animated fadeInDown">
    <div class="ui container">
        <div class="right menu">
            <a th:href="@{/admin/blogs/input}" class="active teal item">发布</a>
            <a th:href="@{/admin/blogs}" class="item">列表</a>
        </div>
    </div>
</div>

<div class="my-padding-tb-large my-container-small">
    <div class="ui container">
        <form id="blog-form" action="#" th:object="${blog}" th:action="@{/admin/blogs}" method="post" class="ui form">
            <input type="hidden" name="isPublished">
            <input type="hidden" name="id" th:value="*{id}">
            <div class="field required animated fadeInUp">
                <div class="ui labeled input">
                    <div class="ui teal basic label">
                        标题
                    </div>
                    <input type="text" name="title" placeholder="标题" th:value="*{title}">
                </div>
            </div>

            <div class="required field animated fadeInUp">
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea placeholder="博客内容" name="content" style="display: none" th:text="*{content}"></textarea>
                </div>
            </div>
            <div class="two fields animated fadeInUp">
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">分类</label>
                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="type.id" th:value="*{type}!=null ? *{type.id}">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.typeName}">错误日志</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class=" field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">标签</label>
                        <div class="ui fluid selection multiple search  dropdown">
                            <input type="hidden" name="tagIds" th:value="*{tagIds}" >
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div class="menu">
                                <div th:each="tag : ${tags}" class="item" data-value="1" th:data-value="${tag.id}" th:text="${tag.tagName}">java</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="required field animated fadeInUp">
                <textarea name="description" th:text="*{description}" placeholder="博客描述..." maxlength="200"></textarea>
            </div>

            <div class="inline fields animated fadeInUp">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend" checked th:checked="*{recommend}" class="hidden">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
            </div>

            <div class="ui error message"></div>

            <div class="ui right aligned container animated fadeInUp">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button type="button" id="save-btn" class="ui secondary button">保存</button>
                <button type="button" id="publish-btn" class="ui teal button">发布</button>
            </div>

        </form>
    </div>


</div>


<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/semantic-ui/2.4.1/semantic.min.js"></script>
<script src="../../static/lib/editormd/editormd.js" th:src="@{/lib/editormd/editormd.js}"></script>

<script>
    $('.menu.tooggle').click(function () {
        $('.my-item').toggleClass('my-mobile-hide');
    });

    $('.ui.dropdown')
        .dropdown({
            on: "hover"
        })
    ;

    $('#save-btn').click(function () {
        $('[name="isPublished"]').val(false);
        $('#blog-form').submit();
    });

    $('#publish-btn').click(function () {
        $('[name="isPublished"]').val(true);
        $('#blog-form').submit();
    });

    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'title',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请输入博客标题'
                }]
            },
            content: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '内容：请输入博客内容'
                }]
            },
            typeId : {
                identifier: 'type.id',
                rules: [{
                    type : 'empty',
                    prompt: '分类：请输入博客分类'
                }]
            },
        }
    });


    //初始化markdown编辑器
    var contentEditor;

    $(function () {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 640,
            syncScrolling: "single",
            path: "/lib/editormd/lib/"
        });
    });
</script>
</body>
</html>